﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace sdamarketing
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // Page.Master.FindControl("AdministrationPanel").Visible = false;
        }

        protected void LogInButton_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet dataSet = Users.authenticateUser(username.Text, password.Text);
                // proveruvam dali e blokiran ili izbrisan userot (ima edno flagce vo baza isBlock 
                if (dataSet.Tables["User"].Rows[0].ItemArray[1].ToString() == "False" && dataSet.Tables["User"].Rows[0].ItemArray[2].ToString() == "False")
                {
                    
                    Session["idUser"] = dataSet.Tables["User"].Rows[0].ItemArray[0].ToString();
                    Session["username"] = username.Text;
                    Session["idRole"] = dataSet.Tables["User"].Rows[0].ItemArray[3].ToString();
                    Response.Redirect("~/Account/Home.aspx");
                }
                else
                {
                    lblError.Text = "Корисничкото име и/или лозинката е/се погрешни";
                }
            }
            catch (Exception)
            {
                lblError.Text = "Корисничкото име и/или лозинката е/се погрешни";
            }
        }
    }
}
